package com.cao.meet.swipelist;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

import com.cao.meet.swipelist.view.CustomListView;
import com.cao.meet.swipelist.view.MyLinearLayout;

import java.util.ArrayList;
import java.util.List;

public class SwipeListActivity extends Activity implements View.OnClickListener,MyLinearLayout.OnScrollListener{
    private CustomListView listView;
    private MergeListAdapter adapter;
    private MyLinearLayout mLastScrollView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_swipe_list);


        listView = (CustomListView) findViewById(R.id.listview);
        final List<MergeListAdapter.DataHolder> items = new ArrayList<MergeListAdapter.DataHolder>();
        for(int i=0;i<20;i++){
            MergeListAdapter.DataHolder item = new MergeListAdapter.DataHolder();
            item.title = "第"+i+"项";
            items.add(item);
        }
        adapter = new MergeListAdapter(this,items,this,this);
        listView.setAdapter(adapter);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.del){
            int position = listView.getPositionForView(v);
            adapter.removeItem(position);
        }
    }

    @Override
    public void OnScroll(MyLinearLayout view) {
        if (mLastScrollView != null){
            mLastScrollView.smoothScrollTo(0,0);
        }
        mLastScrollView = view;
    }

}
